// pages/item/item.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        uid:"",
        nickname:"",
        logo:"",
        campus:"",
        is_like:"",
        pages:1,
        last_page:1,
        },

    chat(){
        wx.navigateTo({
          url: '/pages/chat/chat',
        })
    },

    item(e){
        let id = e.currentTarget.dataset.id;
        wx.navigateTo({
          url: '/pages/details/details?id='+id,
        })

    },

    like(e){
        let uid = e.currentTarget.dataset.uid;
        let _this = this;
        wx.request({
          url: 'http://www.campus.com/campus/Campus/userLike',
          data:{uid},
          success:function(res){
              if(res.data.code==0){
                  _this.setData({
                      is_like:1,
                  })
                  wx.showToast({
                    title: '关注成功',
                  })
              }
          }
        })
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        let uid = options.uid;
        let _this = this;
        wx.request({
          url: 'http://www.campus.com/campus/Campus/userData',
          data:{uid},
          success:function(res){
              _this.setData({
                  uid:res.data.user.uid,
                  nickname:res.data.user.nickname,
                  logo:res.data.user.logo,
                  campus:res.data.data.data,
                  is_like:res.data.user.is_like,
                  pages:res.data.data.current_page,
                  last_page:res.data.data.last_page
              })
          }
        })

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
        let spage = this.data.pages+1;
        let  uid = 1;
        if(spage>this.data.last_page){
            wx.showToast({
              title: '数据加载完毕',
              icon:'none'
            })
            return false;
        }
        let _this = this;
        wx.request({
            url: 'http://www.campus.com/campus/Campus/userData',
            data:{uid},
            success:function(res){
                console.log(res);
                let arr = res.data.data.data;
                arr.forEach(function(v,k){
                    _this.data.campus.push(v);
                });
                _this.setData({
                    uid:res.data.user.uid,
                    nickname:res.data.user.nickname,
                    logo:res.data.user.logo,
                    is_like:res.data.user.is_like,
                    campus:_this.data.campus,
                    pages:spage,
                })
            }
          })
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})